home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Fireworks 3 / Settings / Commands / Document / Center in Document.jsf next >
Encoding:
Text File  |  1999-11-19  |  1.1 KB  |  35 lines

  1. // Copyright (c) 1999 Macromedia. All rights reserved.
  2.  
  3. //Excute the script if there is a selection
  4. if (fw.selection != null && fw.selection.length > 0) {
  5.     // Get the Document Size
  6.     var docWidth = fw.getDocumentDOM().width;
  7.     var docHeight = fw.getDocumentDOM().height;
  8.     var docLeft = fw.getDocumentDOM().left;
  9.     var docTop = fw.getDocumentDOM().top;
  10.  
  11.     // Figure out wwhere the middle of the Document is
  12.     var middleWidth = docWidth/2;
  13.     var middleHeight = docHeight/2;
  14.  
  15.     // Get the selection Size
  16.     var selectBounds = fw.getDocumentDOM().getSelectionBounds();
  17.     var selectLeft = selectBounds.left;
  18.     var selectTop = selectBounds.top;
  19.     var selectRight = selectBounds.right;
  20.     var selectBottom = selectBounds.bottom;
  21.  
  22.     // Figure out where the middle of the selection is
  23.     var selectMiddleWidth = (selectRight - selectLeft)/2;
  24.     var selectMiddleHeight = (selectBottom - selectTop)/2;
  25.  
  26.     // Figure out where we need to move the selection to
  27.     var moveToX = docLeft + middleWidth - selectMiddleWidth - selectLeft;
  28.     var moveToY = docTop + middleHeight - selectMiddleHeight - selectTop;
  29.  
  30.     // Let's move it
  31.     fw.getDocumentDOM().moveSelectionBy({x:moveToX, y:moveToY}, false, false);
  32. }
  33.  
  34.  
  35.